package cc.customer.web.bigEpResoure;

import cc.customer.bigEmport.damain.BigEmp;
import cc.customer.bigEmport.damain.EpRecords;
import cc.customer.bigEmport.damain.EprRecords;
import cc.customer.bigEmport.services.BigEmpRecords;
import cc.customer.bigEmport.services.BigEprRecords;
import cc.customer.common.domain.QueryRequest;
import cc.customer.common.domain.ResponseBo;
import cc.customer.common.utils.FileUtils;
import cc.customer.system.domain.MyUser;
import cc.customer.web.sys.controller.base.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value ="bigEpExport" )
public class BigExportController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(BigExportController.class);

    @Autowired
    private BigEmpRecords bigEmpRecords;
    @Autowired
    private BigEprRecords bigEprRecords;


    @RequestMapping(value = "bigIndex")
    public String getIndex(){
        return "customer/BigEpResource/bigEpExport/bigEpExport_index";
    }
    /**
     * 成功导入的详情的客户信息*/
    @RequestMapping(value = "getExportDetail")
    public String getExportDetail(){return "customer/BigEpResource/bigEpExport/bigEpExport_index_detail";}
    /**dao失败的 客户的信息**/
    @RequestMapping(value = "getExportFalurDetail")
    public String getExportFalurDetail(){return "customer/BigEpResource/bigEpExport/EpExport_index_fail";}

    /**导入批次的结算详情**/
    @RequestMapping(value = "getExportBalance")
    public String getExportBalance(){return "customer/BigEpResource/bigEpExport/bigEpExport_Balance"; }
    /**导入批次的结算详情**/
    @RequestMapping(value = "getExportBalancedetail")
    public String getExportBalancedetail(){return "customer/BigEpResource/bigEpExport/bigEpExport_Balance_detail"; }

    /**
     * 大资源导入的记录 分页查询
     * **/
    @RequestMapping(value = "/getAllBigRecords")
    @ResponseBody
    public Map<String, Object> getAllBigRecords(EpRecords records, QueryRequest request){
        return super.selectByPageNumSize(request, () ->  bigEmpRecords.getAllBigEmpRecords(records));
    }
    /**
     * AI资源导入的记录 分页查询
     * **/
    @RequestMapping(value = "/getAllAIRecords")
    @ResponseBody
    public Map<String, Object> getAllAIRecords(EpRecords records, QueryRequest request){
        return super.selectByPageNumSize(request, () ->  bigEmpRecords.getAllAiEmpRecords(records));
    }
    /**
     * 获取查询批次的模糊查询
     * **/
    @RequestMapping(value = "/getlimitBigRecords")
    @ResponseBody
    public List<EpRecords> getlimitBigRecords(EpRecords records){
        return bigEmpRecords.getOneFiveEmpRecords(records);
    }

    /**获取当前导入记录的 导入失败的客户信息 根据导入的 uuid**/
    @RequestMapping(value = "/getbigEprRecordsByImpUuid")
    @ResponseBody
    public Map<String, Object> getbigEprRecordsByImpUuid(QueryRequest request,String recordsUuid){
        MyUser user = this.getCurrentUser();
        return super.selectByPageNumSize(request, () ->  bigEprRecords.getEprRecordsByExportUuid(recordsUuid,user));
    }

    /**d
     * 大资源批次的结算
     * **/
    @RequestMapping(value = "/banlanceBigRecords")
    @ResponseBody
    public ResponseBo banlanceBigRecords(Long epid,String uuid,String num){
        try {
            MyUser user = this.getCurrentUser();
            String username = user.getUsername();
            int numint= Integer.parseInt(num);
            return bigEmpRecords.balanceEmpRecords(epid,uuid,username,numint);//balanceEmpRecords(records);
        }catch (Exception e){
            logger.error("结算操作失败:"+e.getMessage());
            return ResponseBo.error("结算失败:"+e.getMessage());
        }
    }

    /**获取大资源导入的结算**/

    @RequestMapping(value = "/viewBalanceEmpRecords")
    @ResponseBody
    public ResponseBo viewBalanceEmpRecords(Long epid,String uuid){
        try {
            return bigEmpRecords.viewBalanceEmpRecords(epid,uuid);//balanceEmpRecords(records);
        }catch (Exception e){
            logger.error("结算详情失败:"+e.getMessage());
            return ResponseBo.error("结算详情失败:"+e.getMessage());
        }
    }

    /**大资源客户导出excel**/
    @RequestMapping("/downloadList")
    @ResponseBody
    public ResponseBo downloadList(String uuid){
        try {
            List<EprRecords> list = bigEmpRecords.exportEprRecordsInfo(uuid);
            ResponseBo responseBo = FileUtils.createExcelByPOIKit("客户资料表", list, EprRecords.class);
            return responseBo;
        }catch (Exception e){
            logger.error("导出大资源客户失败："+e.getMessage());
        }
        return ResponseBo.error("导出失败");
    }

}
